package com.chzker.util;

public class PageControl {
	private int page=1; //当前页面
	private int pageSize=0;  //页面显示信息条数
	private int startPage = 1; //首页
	private int prePage; //前一页
	private int nextPage; //下一页
	private int endPage = 0;  //尾页 总共页数
	private int sub1;
	private int sub2;
	

	/***********Function Execute************/
	public String execute(int total,int pageSize,int page){
		this.pageSize=pageSize;
		this.page=page;
		if(total%pageSize!=0){
			endPage=total/pageSize+1;
		}else{
			endPage=total/pageSize;
		}
		if(total<=pageSize){
			this.startPage=0;
			this.prePage=0;
			this.nextPage=0;
			this.endPage=0;
		}else if(page<=1){
			this.prePage=0;
			this.nextPage=2;
			this.sub1=0;
			this.sub2=pageSize;
		}else if(page<endPage){
			this.prePage=page-1;
			this.nextPage=page+1;
			this.sub1=prePage*pageSize;
			this.sub2=page*pageSize;
		}else if(page>=endPage){
			this.prePage=endPage-1;
			this.endPage=0;
			this.nextPage=0;
			this.sub1=prePage*pageSize;
			this.sub2=total;
		}
		
		return "listPage";
	}
	
	/*
	 * Geter And Seters
	 */
	public int getPage() {
		return page;
	}
	public void setPage(int page) {
		this.page = page;
	}

	public int getPageSize() {
		return pageSize;
	}
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}
	public int getStartPage() {
		return startPage;
	}
	public void setStartPage(int startPage) {
		this.startPage = startPage;
	}
	public int getPrePage() {
		return prePage;
	}
	public void setPrePage(int prePage) {
		this.prePage = prePage;
	}
	public int getNextPage() {
		return nextPage;
	}
	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}
	public int getEndPage() {
		return endPage;
	}
	public void setEndPage(int endPage) {
		this.endPage = endPage;
	}

	public int getSub1() {
		return sub1;
	}

	public void setSub1(int sub1) {
		this.sub1 = sub1;
	}

	public int getSub2() {
		return sub2;
	}

	public void setSub2(int sub2) {
		this.sub2 = sub2;
	}
}
